package logic

import (
	"context"
	"gorm.io/gorm"
	"qimao/models/PostgreSQL"

	"qimao/qimaorpc/internal/svc"
	"qimao/qimaorpc/qimaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookUpdateLogic {
	return &BookUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookUpdateLogic) BookUpdate(in *qimaorpc.BookUpdateRequest) (*qimaorpc.BookUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var book PostgreSQL.Book

	book = PostgreSQL.Book{
		Model: gorm.Model{ID: book.ID},
		Title: in.Title,
		Trace: in.Trace,
		Image: in.Image,
	}
	PostgreSQL.DB.Where("id=?", in.BookId).Updates(&book)
	return &qimaorpc.BookUpdateResponse{
		BookId: int64(book.ID),
	}, nil
}
